<template>
	<view class="pop-order-choose-coupon">
		<u-popup ref="store_cart_pop" bgColor="#ffffff" :show="show_pop" mode="bottom" :closeOnClickOverlay="true"
			round="30" @close="handleClose" @open="handleOpen">
			<view class="info-modal-wrap">
				<view class="info-modal-inner">
					<view class="modal-head ">
						<view class="title-box">
							优惠券
						</view>
						<view class="use-tip flex-between">
							<text class="tip">
								请选择优惠券
							</text>
							<!-- <view class="btn flex-center">
									使用推荐优惠
								</view> -->
						</view>
					</view>

					<view class="modal-ctx">
						<scroll-view scroll-y scroll-with-animation class="scroll-container">
							<view class="coupon-wrap">
								<view class="coupon-list">
									<view class="coupon-item" v-for="(item,index) in coupons" :key="index" @click="doCouponPick(item)">
										<view class="bg-box">
											<!-- <image src="@/static/store-detail/coupon-bg.png" mode=""></image> -->
										</view>

										<view class="info-box flex-between">
											<view class="money-box column-flex-center">
												<view class="money-info">
													<text class="huobi">￥</text>
													<text class="value">{{item.jian}}</text>
												</view>
												<view class="tiaojian">
													{{item.tiaojian}}
												</view>
											</view>

											<view class="info">
												<view class="title ellipsis-1">
													<!-- 满39减5元优惠券 -->
													{{item.title}}
												</view>
												<view class="date">
													有效期至：{{item.endTime | formatDate}}
												</view>
											</view>

											<view class="btn-box flex-center">
												<!-- 	<view class="btn flex-center " :class="{picked: item.is_lq == 1 }">
													{{item.is_lq == 1 ? '已选择' :'使用'}}
												</view> -->
												<image v-if="real_payment_money < item.jian" src="@/static/common/no-radio.png" mode=""></image>
												<image v-else-if="coupon_select.id == item.id" src="@/static/common/radio1.png" mode=""></image>
												<image v-else src="@/static/common/radio0.png" mode=""></image>
											</view>
										</view>

									</view>
								</view>
							</view>
						</scroll-view>
					</view>

					<view class="modal-foot">
						<view class="footer-wrap ">
							<view class="btns flex-between">
								<view class="btn btn-cancel flex-center" @click="doCancel()">
									不使用优惠券
								</view>
								<!-- <view class="btn btn-confirm  flex-center" @click="doConfirm()">
									确认
								</view> -->
							</view>
						</view>
					</view>
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				show_pop: false,
				coupons: [],
				coupon_select: {},
				real_payment_money: ''
			}
		},
		computed: {

		},
		watch: {

		},
		methods: {
			init(coupons, real_payment_money) {
				this.$log('选择优惠券', coupons)
				this.real_payment_money = real_payment_money

				this.coupons = coupons;
				this.show_pop = true;
			},
			handleClose() {
				this.show_pop = false;
			},
			handleOpen() {},
			doClose() {
				this.show_pop = false;
			},
			doCouponPick(item) {
				this.$log('选择优惠券', item)
				if (this.real_payment_money < item.jian) {
					return;
				}
				this.coupon_select = item;
				this.$emit('confirm', this.coupon_select)
				this.show_pop = false;
			},
			doCancel() {
				this.coupon_select = {};
				this.$emit('confirm', {})
				this.show_pop = false;
			},
			doConfirm() {
				if (!this.coupon_select.id) {
					this.$alert('请选择优惠券')
					return
				}
				this.$emit('confirm', this.coupon_select)
				this.show_pop = false;
			}
		},
	}
</script>

<style lang="scss" scoped>
	.pop-order-choose-coupon {
		position: relative;
		z-index: 1000;
	}


	.info-modal-wrap {
		width: 574rpx;
		width: 660rpx;
		width: 100%;
		position: relative;
		text-align: left;
		padding-bottom: 0;
		// padding-bottom: calc(64rpx + constant(safe-area-inset-bottom));
		// padding-bottom: calc(64rpx + env(safe-area-inset-bottom));

		.info-modal-inner {
			border-radius: 16rpx;
			overflow: hidden;
			width: 100%;
			padding: 0 0;
			padding-bottom: 0;
			min-height: 400rpx;
			background: #FFFFFF;
		}
	}



	.modal-head {

		// border: 1rpx solid #DDDDDD;
		padding-right: 0;

		.title-box {
			padding: 20rpx 40rpx;
			text-align: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 32rpx;
			color: #000000;
		}

		.use-tip {
			border-top: 1rpx solid #F3F4F8;
			padding: 0 32rpx;
			height: 80rpx;
			background: #FFFFFF;

			.tip {
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #000000;
			}

			.btn {
				padding: 0 16rpx;
				min-width: 176rpx;
				height: 48rpx;
				background: #CB0011;
				border-radius: 24rpx 24rpx 24rpx 24rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #FFFFFF;
			}
		}
	}


	.modal-ctx {
		width: 100%;
		background: #F5F7F9;
		padding: 24rpx 32rpx;
		min-height: 200rpx;
		padding-bottom: 30rpx;
	}

	.scroll-container {
		max-height: calc(100vh - 600rpx);
	}

	.coupon-wrap {}

	.coupon-list {


		.coupon-item {
			position: relative;
			margin-bottom: 20rpx;
			background: #fff;
			height: 262rpx;
			border-radius: 8rpx 8rpx 8rpx 8rpx;
			overflow: hidden;

			&:last-child {
				margin-bottom: 0rpx;
			}

			// .bg-box {
			// 	width: 710rpx;
			// 	height: 146rpx;
			// 	position: relative;
			// 	z-index: 1;

			// 	image {
			// 		width: 710rpx;
			// 		height: 146rpx;
			// 	}
			// }

			.info-box {
				position: absolute;
				z-index: 2;
				left: 0;
				top: 0;
				right: 0;
				bottom: 0;

				.money-box {
					border-right: 1rpx dashed #CB0011;
					width: 260rpx;
					height: 262rpx;
					// background: linear-gradient(180deg, #51B2C7 0%, #CB0011 100%);
					background: #ffffff;

					.money-info {
						.huobi {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 36rpx;
							color: #CB0011;
						}

						.value {
							font-family: PingFang SC, PingFang SC;
							font-weight: bold;
							font-size: 72rpx;
							color: #CB0011;
						}
					}

					.tiaojian {
						margin-top: 10rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #CB0011;
					}
				}

				.info {
					flex: 1;
					overflow: hidden;
					padding: 0 40rpx;
					padding-right: 0;

					.title {
						font-family: PingFang SC, PingFang SC;
						font-weight: bold;
						font-size: 32rpx;
						color: #000000;
					}

					.date {
						margin-top: 40rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 400;
						font-size: 24rpx;
						color: #000000;
					}

				}

				.btn-box {
					width: 80rpx;
					align-self: stretch;

					image {
						width: 40rpx;
						height: 40rpx;
					}
				}

				.btn {

					min-width: 108rpx;
					padding: 0 16rpx;
					height: 48rpx;
					// background: linear-gradient(112deg, #FF8B17 0%, #F54242 46%, #F54242 100%);
					// border-radius: 24rpx 24rpx 24rpx 24rpx;
					// font-family: PingFang SC, PingFang SC;
					// font-weight: 600;
					// font-size: 24rpx;
					// color: #FFFFFF;

					&.picked {
						background: #ccc;
					}


				}
			}

		}
	}



	.footer-wrap {
		padding: 20rpx;

		.safe-fixed-bottom {
			position: relative;

		}


		.btns {


			.btn {
				flex: 1;
				width: 100%;
				height: 80rpx;

				border-radius: 40rpx;

				background: #CB0011;
				font-family: PingFang SC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #FFFFFF;

				&.btn-cancel {
					background: #CB0011;


				}

				&.btn-confirm {
					background: linear-gradient(112deg, #FF8B17 0%, #F54242 46%, #F54242 100%);
				}

				&+.btn {
					margin-left: 24rpx;
				}
			}
		}
	}
</style>